package com.team.employment.web.admin.controller.communal;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.team.employment.common.result.Result;
import com.team.employment.model.enums.BaseStatus;
import com.team.employment.model.enums.EntityType;
import com.team.employment.model.enums.ReleaseStatus;
import com.team.employment.web.admin.custom.audit.StatusAuditStrategyFactory;
import com.team.employment.web.admin.dto.BaseStatusSubmitDto;
import com.team.employment.web.admin.service.BenefitInfoService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;

@Tag(name = "审核状态管理")
@RestController
@RequestMapping("/admin/isStatus")
public class IsBaseStatusController<T> {

    @Autowired
    private StatusAuditStrategyFactory factory;

    @Operation(summary = "单个修改审核状态")
    @PutMapping("updateOne")
    public Result updateOne(@RequestParam String entityType,@RequestParam Long id,@RequestParam BaseStatus baseStatus) {
        IService<T> service = factory.getService(entityType);

        //因为使用Lambda形式的条件构造器在构造具体条件时，需要知道具体的实体类；
        /*
            优点：
                ✅ 完全动态，适用于任意实体类型
                ✅ 避免 Lambda 形式对具体实体类的依赖
         */
        UpdateWrapper<T> updateWrapper = new UpdateWrapper<>();
        updateWrapper.eq("id",id).set("status",baseStatus);
        service.update(updateWrapper);

        return Result.ok();
    }

    @Operation(summary = "批量修改审核状态")
    @PutMapping("updateMore")
    public Result updateMore( @RequestParam String entityType,@RequestBody BaseStatusSubmitDto baseStatusSubmitDto) {
        IService<T> service = factory.getService(entityType);
        UpdateWrapper<T> updateWrapper = new UpdateWrapper<>();
        baseStatusSubmitDto.getIds().forEach(id->{
            updateWrapper.eq("id",id).or();
        });
        updateWrapper.set("status",baseStatusSubmitDto.getBaseStatus());
        service.update(updateWrapper);
        return Result.ok();

    }


}
